package LeetCode.month01.day20;

public class No2379 {
    public static void main(String[] args) {
        System.out.println(minimumRecolors("BBBBBWWBBWBWBWWWBWBWBBBBWBBBBWBWBWBWBWWBWWBWBWWWWBBWWWWBWWWWBWBBWBBWBBWWW",29));
    }
    public static int minimumRecolors(String blocks, int k) {
        int res = Integer.MAX_VALUE;
        int count = 0;
        int len = blocks.length();
        for (int i = 0; i < k; i++) {
            char c = blocks.charAt(i);
            if(c=='W') count++;
        }
        res = count;
        for (int i = k; i < len; i++) {
            char c = blocks.charAt(i);
            if(c=='W') count++;
            if(blocks.charAt(i-k)=='W') count--;
            res = Math.min(res,count);
        }
        return Math.min(res,count);
    }
}
